// https://nuxt.com/docs/api/configuration/nuxt-config
import path from 'path';
import fs from 'fs';
import { createSvgIconsPlugin } from 'vite-plugin-svg-icons';

export default defineNuxtConfig({
	ssr: true, // 必须为 true
	runtimeConfig: {
		public: {
			baseUrl: 'http://47.239.232.212:48080',
		},
	},
	nitro: {
        output: {
            dir: 'output_dist'
        },
		routeRules: {
			// 规则二：将 /admin-api/** 的请求代理到 47.111.158.18
			'/admin-api/**': {
				proxy: 'http://47.239.232.212:48080/admin-api/**',
			},
		},
	},

	hooks: {
		'nitro:build:public-assets': async nitro => {
			const sourcePath = path.resolve(__dirname, 'ecosystem.config.js');
			const targetPath = path.resolve(nitro.options.output.dir, 'ecosystem.config.js');
			fs.copyFileSync(sourcePath, targetPath);
			console.log(`✅ 已复制 ecosystem.config.js：${sourcePath} → ${targetPath}`);
		},
	},
	compatibilityDate: '2025-06-09',
	devtools: { enabled: false },
	devServer: {
		port: Number(process.env.PORT || 3000),
	},
	typescript: {
		typeCheck: true,
	},
	modules: [
		'@element-plus/nuxt',
		'@pinia/nuxt',
		'@pinia-plugin-persistedstate/nuxt',
		'@nuxtjs/i18n',
	],
	// 构建配置
	build: {
		transpile: ['swiper'],
	},
	i18n: {
		strategy: 'prefix_except_default',
		locales: ['en-US', 'zh-CN', 'zh-HK'],
		defaultLocale: 'zh-HK',
		vueI18n: '@@/i18n/config.ts',
		detectBrowserLanguage: false, // 禁用浏览器语言检测
	},
	css: [
		'element-plus/dist/index.css',
		'element-plus/theme-chalk/display.css',
		'@@/assets/styles/index.less',
		'@@/assets/styles/aos-custom.css',
		'swiper/css',
		'swiper/css/pagination',
		'swiper/css/navigation',
	],
	vite: {
		plugins: [
			createSvgIconsPlugin({
				iconDirs: [path.resolve(process.cwd(), 'assets/icons/svg')],
			}),
		],
	},
});
